package demo03.Lambda;

/*
 * 比较原来实现多线程的方式，通过普通方法lambda表达式*/
public class Demo01Runnable {
    public static void main(String[] args) {
        //2.实例化接口实现类
        RunnableImpl runnable = new RunnableImpl();
        //3.创建Thread对象，构造方法中传递接口实现类对象
        Thread t = new Thread(runnable);
        //4.使用Thread对象开启多线程
        t.start();

        //简化第一步写上匿名内部类简化接口实现类
        Runnable runnable1 = new Runnable() {

            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "新线程创建了");
            }
        };
        Thread t1 = new Thread(runnable1);
        t1.start();
        //简化第二步把接口实现类对象直接放入Thread构造方法中
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "新线程创建了");
            }
        });
        t2.start();
        //简化第三步把Thread对象省略，用匿名写法
        new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "新线程创建了");
            }
        }).start();
        //lambda表达式
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "新线程创建了");
        }).start();
        //简化的lambda表达式
        new Thread(()-> System.out.println("新线程创建了"));





    }
}
